<?php

// test couchdb connection with php
// To get this example code running you need to install CouchDB on your system and have it running on port 5984. If you use a different machine or port, change the first two lines of code to your specific values. 
// CouchDB has all sorts of special URLs for specific tasks. The /_all_dbs URL gives us a list of all the database

include 'CouchDBFactory.php';

// we get a new CouchDB object that will use the 'pastebin' db
$couchdb = new CouchDB('ospf_simulator');
try 
{
	$result = $couchdb->getJsonTest();
    // $result = $couchdb->get_item("c20e2495b884f5bdedfd249e8e000484");
} catch(CouchDBException $e) 
{
    die($e->errorMessage()."\n");
}

print_r($result->body);

// here we get the decoded json from the response
// $all_docs = $result->getBody(true);

// then we can iterate through the returned rows and fetch each item using its id.
// foreach($all_docs->rows as $r => $row) {	
    
	// $couchDBResponse = $couchdb->get_item($row->id);	
	// $datatemp = $couchdb->get_item($row->id);
	
	// print_r($datatemp);
	// print_r($couchDBResponse->getBody(true));
	// print_r($couchdb->get_item($row->id)->body);
// }

// print_r($result);

// // if we want to find only pastebin items that are currently published, we need to do a little more.
// // below, we create a view using a javascript function passed in the post data.
// $map = <<<MAP
// function(doc) {
    // if(doc.status == 'published') {
        // emit(doc.title, {docTitle: doc.title, docBody: doc.body});
    // }
// }
// MAP;
// $view = '{"map":"'.$map.'"}';

// // we set the method to POST and send the request to couch db's /_temp_view. the text of the view is passed as post data.
// // this javascript function will return documents whose 'status' field contains 'published'.
// // note that we set the content type to 'text/javascript' for posts in our couchdb class.
// $view_result = $couchdb->send('/_temp_view', 'post', $view);
// print $view_result->getBody();
?>